<?php
/**
 * ClassName: MessageService
 * Description:
 * @Author 周昌
 * @Create 2024/1/5 13:13
 */

namespace service\admin;


use model\ArchivesModel;
use service\BaseService;

class MessageService extends BaseService
{
    protected static $model='model\MessageModel';
    public static $message_type=[0=>'消费',1=>'预约',2=>'充值',3=>'签到',4=>'问诊结束',7=>'未支付'];
    public static $message_type_index=['consume'=>0,'reservation'=>1,'recharge'=>2,'sign_in'=>3,'ask'=>4,'unpaid'=>7];

    /**
     * #User: Administrator
     * #Time: 2024/1/5 14:52
     * #Author:周昌
     * #Description: 添加消息
     * @param $member_id
     * @param $type //0=>'消费',1=>'预约',2=>'充值',3=>'签到',4=>'问诊结束',7=>'未支付'
     * @param null $money 金额
     * @param null $card_id 卡id
     * @param null $archives_id 患者档案id
     * @return array
     */
    public static function addMessage($member_id,$type,$money=null,$card_id=null,$archives_id=null,$gift_money=null)
    {
        $data=[
            'member_id'=>$member_id,
            'type'=>$type,
            'addtime'=>time(),
        ];
        if($money){
            $data['money']=$money;
        }
        switch ($type){
            case 0:
                if($card_id){
                    $data['title']=CardCateService::getCateName($card_id);
                }else{
                    $data['title']='线下支付';
                }
                $data['explain']='消费金额'.$money.'元';//卡名或线下支付
                break;
//            case 1:
//                $data['title']=
//                $data['explain']='预约成功';//人名
//                break;
            case 2:
                $data['title']=CardCateService::getCateName($card_id);
                $data['explain']='充值成功'.$money.'元';//卡名
                if($gift_money){
                    $data['explain'].='赠送金额'.$gift_money.'元';
                }
                break;
            case 3:
                $data['title']=ArchivesModel::getValue(['id'=>$archives_id],'name');
                $data['explain']='签到成功';//人名
                break;
            case 4:
                $data['title']=ArchivesModel::getValue(['id'=>$archives_id],'name');
                $data['explain']='问诊结束';//人名
                break;
//            case 7:
//                $data['explain']='待支付金额'.$money.'元';//人名
//                break;
        }
        return self::add($data);
    }

}